<?php
    session_start();
    include('top.php');
    $sid = $_POST['specialityid'];
    if (empty($sid)) { ?>
    <div class="ui_div_border" id="ui_div_border">
        <table class="ui_border ui_state_visible ui_state_focus ui_state_lock" id="alert">
            <tbody>
                <tr>
                    <td class="ui_lt"></td>
                    <td class="ui_t"></td>
                    <td class="ui_rt"></td>
                </tr>
                <tr>
                    <td class="ui_l"></td>
                    <td class="ui_c">
                        <div class="ui_inner">
                            <table class="ui_dialog">
                                <tbody>
                                    <tr>
                                        <td colspan="2">
                                            <div class="ui_title_bar">
                                                <div class="ui_title" unselectable="on" style="cursor: move;">警告</div>
                                                <div class="ui_title_buttons"><a class="ui_close" href="javascript:void(0);" title="关闭(esc键)" style="display: inline-block;">×</a></div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="ui_icon" style=""><img src="/static/img/alert.gif" class="ui_icon_bg"></td>
                                        <td class="ui_main" style="width: 200px; height: auto;">
                                            请选择报考专业
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <div class="ui_buttons" style="">
                                                <input type="button" value="确定" class="ui_state_highlight" onclick="location.href='select-home.php';">
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </td>
                    <td class="ui_r"></td>
                </tr>
                <tr>
                    <td class="ui_lb"></td>
                    <td class="ui_b"></td>
                    <td class="ui_rb" style="cursor: auto;"></td>
                </tr>
            </tbody>
        </table>
    </div>
    <?php } else {
    $s_sql = "select * from speciality where id = $sid";
    $s_result = mysqli_query($link,$s_sql);
    $s_row = mysqli_fetch_array($s_result);
?>
        <style>
            #ui_div_border {
                visibility: hidden;
            }
        </style>
        <div class="home-body">
            <?php include('info.php'); ?>
                <div class="home-container">
                    <div class="home-side-by-side-no">1.选择招生对象</div>
                    <div class="home-side-by-side-no">2.填写个人信息</div>
                    <div class="home-side-by-side-no">3.选择专业</div>
                    <div class="home-side-by-side-yes">4.报名确认</div>
                </div>

                <div class="home-container-body">
                    <div class="home-side-by-side-start" style="width: 300px;">
                        <h2 class="home-title">报名确认</h2>
                        <div>
                            <form method="post" id="selectFrom">
                                <table width="100%">
                                    <tr>
                                        <th class="result-th">专业代码</th>
                                        <th class="result-th" width="600">专业名称</th>
                                        <th class="result-th">确认提交</th>
                                    </tr>
                                    <tr>
                                        <td class="select-td" height="100">
                                            <?php echo $sid ?>
                                        </td>
                                        <td class="select-td">
                                            <input type="text" class="index_input" name="speciality" value="<?php echo $s_row['name']; ?>" readonly="readonly">
                                        </td>
                                        <td class="select-td">
                                            <input type="submit" id="select-ok" class="my-home-submit" value="确认">
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </div>
                    </div>
                </div>
        </div>
        <div class="ui_div_border" id="ui_div_border">
            <table class="ui_border ui_state_visible ui_state_focus ui_state_lock" id="alert">
                <tbody>
                    <tr>
                        <td class="ui_lt"></td>
                        <td class="ui_t"></td>
                        <td class="ui_rt"></td>
                    </tr>
                    <tr>
                        <td class="ui_l"></td>
                        <td class="ui_c">
                            <div class="ui_inner">
                                <table class="ui_dialog">
                                    <tbody>
                                        <tr>
                                            <td colspan="2">
                                                <div class="ui_title_bar">
                                                    <div class="ui_title" unselectable="on" style="cursor: move;">警告</div>
                                                    <div class="ui_title_buttons"><a class="ui_close" href="javascript:void(0);" title="关闭(esc键)" style="display: inline-block;">×</a></div>
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="ui_icon" style=""><img src="/static/img/alert.gif" class="ui_icon_bg"></td>
                                            <td class="ui_main" style="width: 200px; height: auto;">
                                                <div id="selectResult"></div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                <div class="ui_buttons" style="">
                                                    <input type="button" value="确定" class="ui_state_highlight" onclick="location.href='point.php';">
                                                </div>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </td>
                        <td class="ui_r"></td>
                    </tr>
                    <tr>
                        <td class="ui_lb"></td>
                        <td class="ui_b"></td>
                        <td class="ui_rb" style="cursor: auto;"></td>
                    </tr>
                </tbody>
            </table>
        </div>
        <script type="text/javascript" src="static/js/jquery-3.6.0.min.js"></script>
        <script type="text/javascript">
            const closeButton = document.querySelector('.ui_close');
            const confirmButton = document.querySelector('.ui_state_highlight');
            const uiDivBorder = document.getElementById('ui_div_border');

            closeButton.addEventListener('click', function() {
                uiDivBorder.style.visibility = 'hidden';
            });

            confirmButton.addEventListener('click', function() {
                uiDivBorder.style.visibility = 'hidden';
            });

            document.addEventListener('DOMContentLoaded', function() {
                const nextButton = document.getElementById('select-ok');
                const uiDivBorder = document.getElementById('ui_div_border');

                nextButton.addEventListener('click', function() {
                    uiDivBorder.style.visibility = 'visible';
                });
            });

            $(document).ready(function() {
                $('#selectFrom').on('submit', function(e) {
                    e.preventDefault();
                    var formData = $(this).serialize();

                    $.ajax({
                        url: 'update.php?action=select',
                        type: 'POST',
                        data: formData,
                        success: function(response) {
                            $('#selectResult').empty();
                            $('#selectResult').html(response);
                        },
                        error: function(error) {
                            console.log(error);
                            $('#selectResult').html('失败，请稍后再试。');
                        }
                    });
                });
            });
        </script>
        <?php } include('bottom.php'); ?>